<template>
	<view class="wrap">
		<u-swiper :height="270" :list="imgList" :title="false" @click="imgListClick"></u-swiper>
		<view class="workbench-title">日常办公</view>
		<view class="toolbar">
			<u-grid class="grid" :col="4" :border="false">
				<u-grid-item :index="0" @click="navTo('/pages/work-order/index')" >
					<view class="home-icon icon-color04">
						<i class="iconfont icon-transaction-order"></i>
					</view>
					<view class="grid-text">我的工单</view>
				</u-grid-item>
				<u-grid-item :index="0" @click="navTo('/pages/work-order/pool')" >
					<view class="home-icon icon-color05">
						<i class="iconfont icon-xinwen"></i>
					</view>
					<view class="grid-text">工单池</view>
				</u-grid-item>
			</u-grid>
		</view>
		<u-divider>已经到底了</u-divider>
	</view>
</template>

<script>
import ds from '@/api/service/service.js'
import storeSer, { store } from '@/api/service/store-service.js'
import { queryAppVersion } from '@/api/system/app.js'
import { isUpgradeAble, confirmUpgrade } from '@/components/upgrade/upgrade.vue'

export default {
	data() {
		return {
			imgList: [
				{image: '/static/assets/banner/banner01.png'}
			],
			// 菜单
			routes: []
		}
	},
	async onLoad (params) {
		await this.$onLaunched
		let user = this.getCurrentUser()
		if (!user) {
			return true
		}
		// 是否从服务端查询菜单
		let isQuery = true
		// 查看网络状态，有网则在线查询，无网则本地缓存取
		try {
			isQuery = await this.hasNetwork()
		} catch (e) {
			isQuery = false
		}
		// 由欢迎页面跳转的或离线登录的不需要查询菜单
		if (params.source === 'welcome' || !this.isOnline()) {
			isQuery = false
		}
		// 初始化视图
		this.initView({ isQuery })
		// 版本检测
		// if (!this.$store.state.isAppInit) {
		// 	this.$store.state.isAppInit = true
		// 	this.initUpgrade()
		// }
	},
	async onShow () {
		await this.$onLaunched
	},
	methods: {
		initView ({ isQuery }) {

		},
		// 版本升级
		async initUpgrade () {
			// 是否需要更新
			let b = await isUpgradeAble()
			if (!b) {
				return true
			}
			// 有无网络
			b = await this.hasNetwork()
			if (!b) {
				return true
			}
			// #ifdef APP-PLUS
			return queryAppVersion().then(res => {
				res = res || {}
				// 本地版本与查询的版本不一致则提示更新
				if (String(res.code) !== '200' || !res.data) {
					return true
				}
				const systemInfo = uni.getSystemInfoSync()
				const currentVersionCode = parseFloat(systemInfo.appVersionCode || 0)
				if (!res.data?.version || currentVersionCode >= res.data?.version) {
					return true
				}
				// 下载更新
				store.setItem('upgrade-data', res.data)
				// 确认
				confirmUpgrade({ message: '发现新版本，是否下载更新？' }).then(b => {
					b && uni.reLaunch({
						url: '/pages/sys/user/upgrade?source=workbench'
					})
				})
				return false
			})
			// #endif
			return true
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			})
		},
		imgListClick(index) {
			console.log(`点击了第${index + 1}页图片`)
		},
		itemClick(index) {
			console.log(index);
		}
	}
};
</script>
<style lang="scss">
@import 'index.scss';
.banner-box{
	padding: 0 2%;
	width: 96%;
	height: 170rpx;
	margin: 30rpx 0 30rpx;
}
.u-swiper-wrap{
	padding:0 10px;
}

.banner-pic{
	width: 47%;
	float: left;
	display: inline-block;
	margin: 0 1.5%;
}
.banner-pic image{
	width: 100%;
	height: 170rpx;
	border-radius: 12rpx;
	box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
}

.u-mode-light-info{
  background-color: #ffffff;
  color: #666666;
  border: 1px solid #e9ecf6;
	font-size: 12px;
	padding: 2px 8px;
	position: relative;
	top:-3px;
}
.workbench-title{
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
	padding: 15px 30rpx;
}
 .home-icon i.icon-tongzhi{
	font-size: 22px;
 }
</style>
